<?php js_validate();?>
<form id="form-validated" class="input" action="<?php echo $own_links;?>save" method="post">
		<input type="hidden" name="user_id" id="user_id" value="<?php echo isset($val->user_id)?$val->user_id:'';?>" />
		<table class="table-form">
			<tr>
				<td>Karyawan</td>
				<td>
					<select name="user_employee" class="validate[required,ajax[ajax_user_emp]]" id="user_employee">
						<option value="">Pilih Karyawan</option>
						<?php
						if(count($employee['data'])>0){
							foreach($employee['data'] as $r){
								$t = isset($val->user_employee_id)?$val->user_employee_id:"";
								$s = ($r->employee_id==$t)?"selected='selected'":'';
								echo "<option value='".$r->employee_id."' $s >".$r->employee_fullname."</option>";
							}
						}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td>Group Akses</td>
				<td>
					<select name="user_group" class="validate[required]" id="user_group">
						<option value="">Pilih Level Group</option>
						<?php
						if(count($group['data'])>0){
							foreach($group['data'] as $r){
								$t = isset($g->group_id)?$g->group_id:"";
								$s = ($r->id==$t)?"selected='selected'":'';
								echo "<option value='".$r->id."' $s >".$r->group_name."</option>";
							}
						}
						?>
					</select>
				</td>
			</tr>
			
			<tr valign="top">
				<td>User Asuransi</td>
				<td>
					<select name="user_asuransi" id="user_asuransi">
						<option value="">Pilih Asuransi</option>
						<?php
						if(count($asuransi['data'])>0){
							foreach($asuransi['data'] as $r){
								$t = isset($val->user_asuransi)?$val->user_asuransi:"";
								$s = ($r->asuransi_id==$t)?"selected='selected'":'';
								echo "<option value='".$r->asuransi_id."' $s >".$r->asuransi_name."</option>";
							}
						}
						?>
					</select><br />
					<i class="to">*) Jika ingin membuat user untuk pihak asuransi, silahkan dipilih asuransinya</i>
				</td>
			</tr>
			
			<tr valign="top">
				<td>User Cabang</td>
				<td>
					<select name="user_cabang" id="user_cabang">
						<option value="">Pilih Cabang </option>
						<?php
						if(count($cabang['data'])>0){
							foreach($cabang['data'] as $r){
								$t = isset($val->user_cabang)?$val->user_cabang:"";
								$s = ($r->cabang_id==$t)?"selected='selected'":'';
								echo "<option value='".$r->cabang_id."' $s >".$r->cabang_name."</option>";
							}
						}
						?>
					</select><br />
					<i class="to">*) Jika ingin membuat cabang, silahkan dipilih cabang</i>
				</td>
			</tr>
			
			<tr>
				<td>Username</td>
				<td>
				<?php if(!isset($val->user_name)){?>
					<input type="text" id="user_name" name="user_name" 
					class="validate[required,length[0,15],ajax[ajax_user_user]]"
					size="40" value="" />
				<?php }else{ 
					echo "<b>";
					echo isset($val->user_name)?$val->user_name:'';
					echo "</b>";
					?>
					<input type="hidden" value="<?php echo isset($val->user_name)?$val->user_name:'';?>" name="user_name" />
					<?php
				}?>
				</td>
			</tr>
			
			<tr>
				<td>Password</td>
				<td><input type="password" id="user_password" name="user_password" <?php echo isset($val->user_password)?'':'class="validate[required,length[6,11]]"';?> size="30" value="" /></td>
			</tr>
			<tr>
				<td>Ulangi Password</td>
				<td><input type="password" id="user_password2" name="user_password2" 
				<?php echo isset($val->user_password)?'':'class="validate[required,confirm[user_password]]"';?> size="30" value="" /></td>
			</tr>
			<tr>
				<td>Status User</td>
				<td>
					<select id="user_status" name="user_status" class="validate[required]">
						<option value="1" <?php echo (isset($val->user_status)&& $val->user_status=="1")?'selected="selected"':'';?>>Aktif</option>
						<option value="0"  <?php echo (isset($val->user_status)&& $val->user_status=="0")?'selected="selected"':'';?> >Non Aktif</option>
					</select>
				</td>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr>
				<td><input type="reset" onclick="document.location='<?php echo $own_links;?>'" class="btnbatal" value="Batal" /></td>
				<td align="right"><input type="submit" class="btnsimpan" value="Simpan" /></td>
			</tr>
		</table>
	</form>
	
	<script>
	$('#user_cabang').change(function(){
		$('#user_asuransi').val("");
	});
	
	$('#user_asuransi').change(function(){
		$('#user_cabang').val("");
	});
	</script>